package com.meichis.mcsappframework.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.meichis.mcsappframework.R;


public class MyAlertDialog extends AlertDialog implements OnClickListener {

    private TextView tv_title, tv_message;
    private String title, message;
    private SureClickListener mclicklistener;
    private CancelClickListener CancelClick;

    private Button btn_OK;

    public interface SureClickListener {
        public void onClick(View v);
    }

    public interface CancelClickListener {
        public void onClick(View v);
    }

    public MyAlertDialog(Context context, String title, String message) {
        super(context);
        this.title = title;
        this.message = message;
    }

    public MyAlertDialog(Context context, String title, String message, SureClickListener clicklistener) {
        super(context);
        this.title = title;
        this.message = message;
        mclicklistener = clicklistener;
    }

    public MyAlertDialog(Context context, String title, String message, SureClickListener clicklistener, CancelClickListener cancelClick) {
        super(context);
        this.title = title;
        this.message = message;
        mclicklistener = clicklistener;
        CancelClick = cancelClick;
    }

    @Override
    public void setTitle(CharSequence title) {
        tv_title.setText(title);
    }

    public void setBtnBackgroundResource(int bgReID) {
        btn_OK.setBackgroundResource(bgReID);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.mydialog);

        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_message = (TextView) findViewById(R.id.tv_message);
        tv_message.setText(message);
        if (!title.equals("0")) setTitle(title);
        btn_OK = (Button) findViewById(R.id.btn_OK);
        btn_OK.setOnClickListener(this);
        findViewById(R.id.ibtn_Close).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        dismiss();

        if (v.getId() == R.id.ibtn_Close) {
            if (CancelClick != null) CancelClick.onClick(v);
        } else if (v.getId() == R.id.btn_OK) {
            if (mclicklistener != null) mclicklistener.onClick(v);
        }

    }

}
